home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-10-02 | 895 b | 41 lines | [TEXT/ttxt] |
- \ sort -- Provides a shell sort for arrays of 4-byte elements.
- \ 11/30/84 ssg Version 1.0
- \ 12/17/84 ssg Made into a module
- \ Commented-out sysTimer support
- Decimal
-
- :Module SortMod
-
- \ ( addr1 addr2 -- ) Exchanges 2 4-byte values.
- : exchange 2dup @ swap @ rot ! swap ! ;
-
- \ Shellsorts an array of n 4-byte elements beginning at baseaddr.
- \ comp is the cfa of a word which will compare two elements.
- \ Adapted from Software Tools in Pascal, p. 110.
- : sort { baseaddr n compWord \ gap jj jg -- }
- n 2/ -> gap
- BEGIN
- gap 0 >
- WHILE
- n 1+ gap 1+
- DO i gap - -> jj
- BEGIN
- jj 0 >
- WHILE
- jj gap + -> jg
- baseaddr jj 1- 4* +
- baseaddr jg 1- 4* + ( addr:e1 addr:e2 )
- 2dup swap @ swap @ ( addr:e1 addr:e2 e1 e2 )
- exec> compWord 0 <=
- IF 2drop 0 -> jj
- ELSE exchange
- THEN
- jj gap - -> jj
- REPEAT
- LOOP
- gap 2/ -> gap
- REPEAT
- ;
-
- ;Module
-